import Cookies from 'js-cookie'
import day from 'dayjs'
import duration from 'dayjs/plugin/duration'

day.extend(duration)

const TokenKey = 'x-access-token'
const inFifteenMinutes = day()
  .add(day.duration({ days: 1 }))
  .toDate()
export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token: string) {
  return Cookies.set(TokenKey, token, { expires: inFifteenMinutes, sameSite: 'strict' })
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}
